﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace LibSnesDotNet.Input
{
	public abstract class InputDriver : InputProvider, IDisposable
	{
		string _name;
		Dictionary<InputID, Input> _inputDictionary;
		List<Input> _inputList;
		ReadOnlyCollection<Input> _inputs;

		public string Name { get { return _name; } }
		public ReadOnlyCollection<Input> Inputs { get { return _inputs; } }

		public InputDriver(string name)
		{
			_name = name;
			_inputDictionary = new Dictionary<InputID, Input>();
			_inputList = new List<Input>();
			_inputs = _inputList.AsReadOnly();
		}

		protected void AddInput(Input input)
		{
			_inputDictionary.Add(input.ID, input);
			_inputList.Add(input);
		}

		public Input GetInput(string deviceName, string inputName)
		{
			InputID key = new InputID(_name, deviceName, inputName);

			try
			{
				return _inputDictionary[key];
			}
			catch
			{
				throw new ArgumentException("Input " + _name + deviceName + inputName + " not found.");
			}
		}

		public abstract void Dispose();
	}

}
